<?php

namespace app\home\controller;

use think\Lang;
use think\Db;

/**
 * ============================================================================
 * DSMall多用户商城
 * ============================================================================
 * 版权所有 2014-2028 长沙德尚网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.csdeshang.com
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * 控制器
 */
class Set extends BaseSeller {
  
   protected $template_dir;

    public function _initialize() {
        parent::_initialize();
        Lang::load(APP_PATH . 'home/lang/'.config('default_lang')."/sellergoodsadd.lang.php");
        $this->template_dir = 'default/set/';
    }
  
    public function lists()
    {
      $this->save_pwd();
    }
    #设置密码
    public function save_pwd()
    {   
    	if (request()->isPost()) {
    		if(empty($_POST['old_pwd'])||empty($_POST['new_pwd1'])||empty($_POST['new_pwd2'])){
    			echo "<script>alert('不能为空');location.href='".$_SERVER["HTTP_REFERER"]."';</script>";
    		}
          $old_pwd = md5($_POST['old_pwd']);
          $uinfo = Db::name('member')->where(['member_id'=>$_SESSION['home']['member_id']])->find();
          if($old_pwd == $uinfo['member_password']){
             if($_POST['new_pwd1'] == $_POST['new_pwd2']){
               $new_pwd = md5($_POST['new_pwd1']);
               $res = Db::name('member')->where(['member_id'=>$_SESSION['home']['member_id']])->data(['member_password'=>$new_pwd])->update();
               if($res){
                echo "<script>alert('修改成功');location.href='".$_SERVER["HTTP_REFERER"]."';</script>";
               }else{
                echo "<script>alert('修改失败');location.href='".$_SERVER["HTTP_REFERER"]."';</script>";
               }
             }else{
             	echo "<script>alert('两次密码不相同');location.href='".$_SERVER["HTTP_REFERER"]."';</script>";
             }
          }else{
          	echo "<script>alert('旧密码不正确,请重新输入');location.href='".$_SERVER["HTTP_REFERER"]."';</script>";
          }

    	}
       /* 设置卖家当前菜单 */
        $this->setSellerCurMenu('set');
        $this->setSellerCurItem('set_pwd');
        echo $this->fetch($this->template_dir . 'save_pwd');
        exit;
    }
      
     #退出登录 
     public function logout() {
        session(null);
        $this->redirect('sellerlogin/login');
    }

    /**
     *    栏目菜单
     */
    function getSellerItemList() {
        $item_list = array(
            array(
                'name' => 'set_pwd',
                'text' => lang('set_pwd'),
                'url' => url('Set/lists'),
            ),
        );     
        return $item_list;
    }



}

?>
